package org.minos.edit.view
{
	import flash.events.Event;
	import org.minos.edit.EditFacate;
	import org.minos.edit.model.AssetsProxy;
	import org.minos.edit.view.components.InitInfoPane;
	import org.minos.edit.view.components.SceneTable;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class InitInfoMediator extends Mediator
	{
		public static const NAME : String = "InitInfoMediator";
		
		public function InitInfoMediator( v : InitInfoPane )
		{
			super( NAME , v );
		}
		
		public function get initInfo() : InitInfoPane
		{
			return viewComponent as InitInfoPane;
		}
		
		override public function onRegister() : void
		{
			super.onRegister();
			initInfo.getChildrenBtn().addActionListener( __onChildrenBtnClick );
			initInfo.getStartBtn().addActionListener( __onStartBtnClick );
			initInfo.getWinBtn().addActionListener( __onWinBtnClick );
			initInfo.getLoseBtn().addActionListener( __onLoseBtnClick );
		}
		
		override public function onRemove() : void
		{
			super.onRemove();
			initInfo.getChildrenBtn().removeActionListener( __onChildrenBtnClick );
			initInfo.getStartBtn().removeActionListener( __onStartBtnClick );
			initInfo.getWinBtn().removeActionListener( __onWinBtnClick );
			initInfo.getLoseBtn().removeActionListener( __onLoseBtnClick );
		}
		
		override public function listNotificationInterests() : Array
		{
			return [ SceneTable.LABEL_CHANGED ];
		}
		
		override public function handleNotification( notification : INotification ) : void
		{
			super.handleNotification( notification );
			switch ( notification.getName() )
			{
				case SceneTable.LABEL_CHANGED: 
					initInfo.getChildrenTf()[ "setText" ]( initInfo.childrenAry );
					break;
				default: 
			}
		}
		
		private function __onLoseBtnClick( e : Event ) : void
		{
			selectFileSWF( initInfo.getLoseTf() );
		}
		
		private function __onWinBtnClick( e : Event ) : void
		{
			selectFileSWF( initInfo.getWinTf() );
		}
		
		private function __onStartBtnClick( e : Event ) : void
		{
			selectFileSWF( initInfo.getStartTf() );
		}
		
		private function __onChildrenBtnClick( e : Event ) : void
		{
			sendNotification( EditFacate.SELECT_SCENE , { tf: initInfo.getChildrenTf() , vo: initInfo , type: "childrenAry" } );
		}
		
		private function selectFileSWF( tf : Object = null ) : void
		{
			sendNotification( EditFacate.SELECT_FILE , { tf: tf } , AssetsProxy.SWF );
		}
	
	}

}